
#include <bur/plctypes.h>

#ifdef _DEFAULT_INCLUDES
	#include <AsDefault.h>
#endif

void _INIT ProgramInit(void)
{

	brsstrcpy((UDINT)&HostMailServer,	(UDINT)&"10.43.10.254");
	brsstrcpy((UDINT)&MailSender,		(UDINT)&"LLMRundlauf@br-automation.com");
	brsstrcpy((UDINT)&MailReceiver,		(UDINT)&"bernhard.trost@br-automation.com");
	brsstrcpy((UDINT)&MailSubject,		(UDINT)&"Status LLM-Rundlauf");
	brsstrcpy((UDINT)&MailText,			(UDINT)&"This text is sent in an email using the AsSmtp library.    Attachment:  ");

	SmtpAttachment.type		= smtpATT_TYPE_FILE;
	SmtpAttachment.pData	= (UDINT)&"FileDevice/TestFile.txt";
	SmtpAttachment.length	= 0;
	SmtpAttachment.pName	= (UDINT)&"TestFile.txt";
	
}





void _CYCLIC ProgramCyclic(void)
{

	switch(Step)
	{
		// wait for command
		case 0:
		break;
		
		// collect data
		case 10:
			Step = 11;
		break;
	
		// send mail
		case 11:
			SmtpSend_0.enable		= 1;
			SmtpSend_0.pHost		= (UDINT)&HostMailServer;		// IP adress of the SMTP server.
			SmtpSend_0.pUser		= 0;							// User name, optional. If 0 is specified, authentication does not take place.
			SmtpSend_0.pPassword	= 0;							// Password,  optional. If 0 is specified, authentication does not take place.
			SmtpSend_0.pSender		= (UDINT)&MailSender;			// Sender name
			SmtpSend_0.pReceiver	= (UDINT)&MailReceiver;			// Receiver string, can also contain several recipients that are separated by ',' or a space.
			SmtpSend_0.pSubject		= (UDINT)&MailSubject;			// Subject string
			SmtpSend_0.pText		= (UDINT)&MailText;				// Text string
			SmtpSend_0.pDomain		= 0;							// Sender domain name, optional, If 0 is specified, "[127.0.0.1]" is entered as the sender domain name.
			SmtpSend_0.pAttachment	= (UDINT)&SmtpAttachment;		// Attachment structure
			SmtpSend_0.pSecurity	= 0;							// not used - future extention
			SmtpSend_0.timeout		= 0;							// Server response timeout, optional. If 0 is specified, the default timeout of 120s is used.
			SmtpSend_0.port			= 0;							// Server port number, optional. If 0 is specified, the default port is used (SMTP: 25).
			SmtpSend_0.attcnt		= 0;	//1;					// attachment counter
			SmtpSend(&SmtpSend_0);
			
			if(SmtpSend_0.status != ERR_FUB_BUSY)
			{
				if(SmtpSend_0.status == ERR_OK)
				{
					Step = 0;
				}
				else
				{
					Step = 99;
				}
			}
			
		break;
	
		// error
		case 99:
		break;
	
	}




}





void _EXIT ProgramExit(void)
{

}

